package com.ljl.ningwei.common.page;

import lombok.Data;

import java.util.ArrayList;
import java.util.List;

/**
 * @author 吕佳乐
 * @version 1.0
 * @date 2025-03-17 20:54
 */
@Data
public class PageInfoByPC<T> {

    /**
     * 页码
     */
    private Integer pageNum = 1;
    /**
     * 页码大小
     */
    private Integer pageSize = 10;

    /**
     * 总记录条数
     */
    private Integer total;

    /**
     * 总页数
     */
    private Integer pageTotal;

    /**
     * 总记录数
     */
    private List<T> list;

    public PageInfoByPC(Integer pageNum, Integer pageSize, Integer total, List<T> list) {
        this.pageNum = pageNum;
        this.pageSize = pageSize;
        this.total = total;
        this.list = list;
        this.pageTotal = (int) Math.ceil(total / pageSize);
    }

    public PageInfoByPC(Integer pageNum, Integer pageSize, Integer total) {
        this.pageNum = pageNum;
        this.pageSize = pageSize;
        this.total = total;
        this.pageTotal = (int) Math.ceil(total / pageSize);
        this.list = new ArrayList<>();
    }

    public static <T> PageInfoByPC of(Integer pageNum, Integer pageSize, int total, List<T> list) {
        return new PageInfoByPC(pageNum, pageSize, total, list);
    }
}
